#ifndef ARMOR_H
#define ARMOR_H

#include <opencv2/opencv.hpp>
#include <vector>

class Armor {
public:
    Armor();
    Armor(const cv::Rect& rect, const cv::Point2f& center, 
          const std::vector<cv::Point2f>& points, int number);
    
    // 获取方法
    cv::Rect getBoundingRect() const { return bounding_rect_; }
    cv::Point2f getCenter() const { return center_; }
    std::vector<cv::Point2f> getPoints() const { return points_; }
    int getNumber() const { return number_; }
    double getConfidence() const { return confidence_; }
    double getDistance() const;
    
    // 设置方法
    void setNumber(int number) { number_ = number; }
    void setConfidence(double confidence) { confidence_ = confidence; }
    void setWorldPoints(const std::vector<cv::Point3f>& points) { world_points_ = points; }
    void setPose(const cv::Mat& rvec, const cv::Mat& tvec);
    
private:
    cv::Rect bounding_rect_;
    cv::Point2f center_;
    std::vector<cv::Point2f> points_;
    std::vector<cv::Point3f> world_points_;
    int number_;
    double confidence_;
    
    // PnP结果
    cv::Mat rvec_;
    cv::Mat tvec_;
    double distance_;
};

#if 1 // Inline implementations to avoid separate translation unit dependency

inline Armor::Armor()
    : bounding_rect_(0,0,0,0), center_(0,0), points_(), number_(-1), confidence_(0.0), distance_(0.0) {}

inline Armor::Armor(const cv::Rect& rect, const cv::Point2f& center, const std::vector<cv::Point2f>& points, int number)
    : bounding_rect_(rect), center_(center), points_(points), number_(number), confidence_(0.0), distance_(0.0) {}

inline void Armor::setPose(const cv::Mat& rvec, const cv::Mat& tvec) {
    rvec_ = rvec.clone();
    tvec_ = tvec.clone();
    if (!tvec_.empty()) {
        // Ensure tvec is double
        cv::Mat t;
        tvec_.convertTo(t, CV_64F);
        if (t.total() >= 3) {
            double x = t.at<double>(0,0);
            double y = t.at<double>(1,0);
            double z = t.at<double>(2,0);
            distance_ = std::sqrt(x*x + y*y + z*z);
        }
    }
}

inline double Armor::getDistance() const {
    return distance_;
}

#endif

#endif